package fonkin.com.wifisignapp.acticity.sign;

import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import fonkin.com.wifisignapp.R;
import fonkin.com.wifisignapp.retrofit.BaseRetrofit;
import fonkin.com.wifisignapp.utils.ReturnVo;
import fonkin.com.wifisignapp.utils.ShowToast;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ErrorApply extends AppCompatActivity {

    EditText scripts;
    SharedPreferences preferences;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_error_apply);
        preferences =  PreferenceManager.getDefaultSharedPreferences(ErrorApply.this);
        scripts = (EditText)findViewById(R.id.apply_scripts);
    }

    public void applyBtn(View view){
        if (scripts.getText().toString().equals("")){
            ShowToast.ShowToastShort("请填写调休说明",ErrorApply.this);
        }else {
            initRetrofit(scripts.getText().toString());
        }

    }

    public void initRetrofit(String scriptsStr){
       String userId = preferences.getString("user_id","");
       String userName = preferences.getString("user_name","");
        BaseRetrofit.GetBaseRetrofit().errorApply(userId,userName,scriptsStr).enqueue(new Callback<ReturnVo<String>>() {
            @Override
            public void onResponse(Call<ReturnVo<String>> call, Response<ReturnVo<String>> response) {
                if (response.isSuccessful()){
                    if (response.body().getCode().equals(1))
                    ShowToast.CenterPicToast("添加成功",ErrorApply.this,R.drawable.ic_check_circle_black_24dp);
                }
            }

            @Override
            public void onFailure(Call<ReturnVo<String>> call, Throwable t) {

            }
        });

    }

    public void errorHistory(View v){
        Intent intent = new Intent(ErrorApply.this,ErrorHistory.class);
        startActivity(intent);
        finish();

    }
}
